<template>
  <view class="container">
    <view class="avatar">
      <!-- 上传组件 -->
      <u-upload
        name="product_img"
        :maxCount="1"
        :fileList="filelist"
        width="100"
        height="100"
      
      />
    </view>

    <view class="content">
      <u-form
        labelPosition="left"
        labelWidth="60"
        :model="service"
        :rules="rules"
        ref="product"
      >
        <!-- 部门 -->
        <u-form-item label="门店" borderBottom >
          <u-input
            v-model="service.store_text"
            disabled
            placeholder="门店未知"
          ></u-input>
         
        </u-form-item>
        <!-- 品牌 -->
        <u-form-item label="手机号" borderBottom>
          <u-input
            v-model="service.mobile"
            disabled
            placeholder="手机号未知"
          ></u-input>
    
        </u-form-item>
        <!-- 名称 -->
        <u-form-item label="车主">
          <u-input v-model="service.contacts" disabled />
        </u-form-item>

        <!-- 商品描述 -->
        <u-form-item label="车牌号" borderBottom>
          <u-input
            placeholder="车牌号未知"
            v-model="service.carnumberplate"
			disabled
          ></u-input>
        </u-form-item>

        <!-- 参数3 -->
        <u-form-item label="创建时间" >
          <u-input
            v-model="service.createtime_text"
            placeholder="创建时间不能为空"
			disabled
          />
        </u-form-item>
        <!-- 全款 -->
        <u-form-item label="保险到期" prop="insure">
          <u-input v-model="service.insure" placeholder="保险到期日期未知" />
        </u-form-item>
        <u-form-item label="车险到期" prop="autoInsurance">
          <u-input
            v-model="service.autoInsurance"
            placeholder="车险到期日期未知"
			
          />
        </u-form-item>
        <u-form-item label="车型">
          <u-input v-model="service.cartype" disabled placeholder="车型未知" />
        </u-form-item>
        <u-form-item label="车颜色">
          <u-input v-model="service.carcolor" disabled placeholder="车颜色未知" />
        </u-form-item>

        <view class="avatar">
          <!-- 上传组件 -->
          <u-upload
            name="product_img"
            :maxCount="1"
            :fileList="filelist1"
            width="100"
            height="100"
          
          />
        </view>

        <!-- 提交按钮 -->
        <u-button
          text="修改服务"
          icon="pushpin"
          size="small"
          type="success"
          :customStyle="btnStyle"
          @click="product"
        />
      </u-form>
    </view>
    <!-- 消息提醒 -->
    <u-toast ref="notice"></u-toast>
  </view>
</template>
  
<script>
export default {
  onLoad(options) {
    this.auth = this.$u.auth.check();

    this.carparkid = options.carparkid ? options.carparkid : 0;

    this.list();
  },

  onReady() {
    this.$refs.product.setRules(this.rules);
  },
  created() {
    this.timer = setInterval(() => {
      let a = this.$u.count.check();
    }, 15000);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
  data() {
    return {
      filelist: [],
	  filelist1:[],
      auth: {},
      carparkid: 0,
      store_text: "",
      thumbs_text: "",
      name: "",
      service: {
		id:"",
		insure:"",
		autoInsurance:"",
		xszImg:"",
		carImg:""
	  },

      rules: {
       
        insure: {
          required: true,
          message: "车保险不能为空",
          trigger: ["blur", "change"],
        },
        autoInsurance: {
          required: true,
          message: "车险不能为空",
          trigger: ["blur", "change"],
        }
      
      },
    };
  },

  methods: {
    product() {
      this.$refs.product
        .validate()
        .then(async () => {
          var data = {
            id: this.carparkid,
            insure: this.service.insure,
            autoInsurance: this.service.autoInsurance,
            adminid: this.auth.id,
            xszImg: this.service.xszimg_text,
            carImg: this.service.carimg_text,
          };

          let result = await this.$u.api.business.carparkedit(data);

          if (result.code) {
            this.$refs.notice.show({
              type: "success",
              message: result.msg,
              duration: 1000,
              complete: () => {
                //返回上一个界面
                uni.$u.route({
                  type: "reLaunch",
                  url: "/pages/business/carpark/list/edit",
                  params: {
                    carparkid: this.carparkid,
                  },
                });
              },
            });
          } else {
            this.$refs.notice.show({
              type: "danger",
              message: result.msg,
              duration: 2000,
            });
          }
        })
        .catch(() => {
          uni.$u.toast("效验失败");
        });
    },

    async list() {
      let data = {
        adminid: this.auth.id,
        carparkid: this.carparkid,
      };
      let result = await this.$u.api.business.carparkinfo(data);
      if (result.code) {
        this.service = result.data;

        if (this.service.carimg_text) {
          // 把一维数组循环出来然后组装一个自己想要的结构
          this.filelist = [{ url: this.service.carimg_text }];
        }
        if (this.service.xszimg_text) {
          // 把一维数组循环出来然后组装一个自己想要的结构
          this.filelist1 = [{ url: this.service.xszimg_text }];
        }
      } else {
        this.$refs.notice.show({
          type: "warning",
          message: result.msg,
        });
      }
    },
  },
};
</script>
  
<style >
.content {
  padding: 20px;
}

.container {
  height: 100%;
  margin: 0 50rpx;
  box-sizing: border-box;
}

.avatar {
  text-align: center;
}

.u-avatar {
  margin: 80rpx auto 40rpx;
}

.xcx {
  width: 200rpx;
  height: 200rpx;
  margin: 80rpx auto 40rpx;
  border-radius: 100%;
  overflow: hidden;
}

.nickname {
  font-size: 14px;
  text-align: center;
}

.title {
  text-align: center;
  margin: 40rpx 0;
  font-size: 14rpx;
}

.avatar .u-upload {
  justify-content: center;
  align-items: center;
  margin: 3em auto;
}

.vedio .u-upload {
  justify-content: center;
  align-items: center;
  margin: 0.3em auto;
}

.vedio {
  text-align: center;
}

.u-vedio {
  margin: 80rpx auto 40rpx;
}
</style>
  